package control;

import javax.servlet.http.HttpServletRequest;

import model.UsuarioCT;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class LoginForm extends ActionForm {
	
	private UsuarioCT usuario = new UsuarioCT();
	
	public UsuarioCT getUsuario() {
		return this.usuario;
	}

	public ActionErrors validate(ActionMapping map, HttpServletRequest req) {
		ActionErrors erros = new ActionErrors();
		if (usuario.getUsuario() == null || usuario.getUsuario().equals("")) {
			erros.add("usuario", new ActionMessage("erro.loginCampoUsuario"));
		}
		if (usuario.getSenha() == null || usuario.getSenha().equals("")) {
			erros.add("senha", new ActionMessage("erro.loginCampoSenha"));
		}

		return erros;
	}

	@Override
	public void reset(ActionMapping map, HttpServletRequest req) {
		this.usuario = new UsuarioCT();
	}
}